import { Body, Controller, Get, Post } from '@nestjs/common';
import { ProductService } from 'src/services/product/product.service';
import { HttpResponse } from 'src/types/http_response.interface';
import { Product } from 'src/types/product.interface';

@Controller('products')
export class ProductController {
  constructor(private readonly productService: ProductService) { }
  @Get()
  async findAllActive(): Promise<HttpResponse<Product[]>> {
    const data = await this.productService.find({ isActive: true });
    return {
      success: true,
      message: 'All active products retrieved successfully',
      data,
    };
  }
  @Post()
  async create(@Body() createProductDtos: Product | Product[]) {
    const data = await this.productService.create(createProductDtos);
    return {
      success: true,
      message: 'Product created successfully',
      data,
    };
  }
  @Get('premium') // 查询最新的6个精品商品
  async findPremium(): Promise<HttpResponse<Product[]>> {
    const data = await this.productService.findPremiumProducts();
    return {
      success: true,
      message: 'findPremiumProducts successfully',
      data,
    };
  }
}
